﻿<phone:PhoneApplicationPage xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit" 
    x:Class="LiveEduWizard.WeekSelector"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:LiveEduWizard"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d" 
    d:DataContext="{d:DesignData ../SampleData/MainViewModelSampleData.xaml}"
    d:DesignHeight="800" d:DesignWidth="480">

    <toolkit:TransitionService.NavigationInTransition>
        <toolkit:NavigationInTransition>
            <toolkit:NavigationInTransition.Backward>
                <toolkit:TurnstileTransition Mode="BackwardIn"/>
            </toolkit:NavigationInTransition.Backward>
            <toolkit:NavigationInTransition.Forward>
                <toolkit:TurnstileTransition Mode="ForwardIn"/>
            </toolkit:NavigationInTransition.Forward>
        </toolkit:NavigationInTransition>
    </toolkit:TransitionService.NavigationInTransition>
    <toolkit:TransitionService.NavigationOutTransition>
        <toolkit:NavigationOutTransition>
            <toolkit:NavigationOutTransition.Backward>
                <toolkit:TurnstileTransition Mode="BackwardOut"/>
            </toolkit:NavigationOutTransition.Backward>
            <toolkit:NavigationOutTransition.Forward>
                <toolkit:TurnstileTransition Mode="ForwardOut"/>
            </toolkit:NavigationOutTransition.Forward>
        </toolkit:NavigationOutTransition>
    </toolkit:TransitionService.NavigationOutTransition>

    <phone:PhoneApplicationPage.Resources>
        <local:WeekGroupConverter x:Key="weekGroupConverter"/>
        <local:VisibilityConverter x:Key="visibilityConverter"/>
        <local:MonthConverter x:Key="monthConverter"/>
    </phone:PhoneApplicationPage.Resources>
    
    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="{StaticResource PhoneBackgroundBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="TIMETABLE" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="weeks" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <toolkit:LongListSelector x:Name="Weeks" ItemsSource="{Binding Timetables, Converter={StaticResource weekGroupConverter}}" Loaded="Weeks_Loaded">
                <toolkit:LongListSelector.GroupItemsPanel>
                    <ItemsPanelTemplate>
                        <toolkit:WrapPanel Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Left" Width="480"/>
                    </ItemsPanelTemplate>
                </toolkit:LongListSelector.GroupItemsPanel>
                <toolkit:LongListSelector.GroupItemTemplate>
                    <DataTemplate>
                        <Grid Background="{StaticResource PhoneAccentBrush}" Margin="12,12,0,0" Height="173" Width="173" HorizontalAlignment="Left" VerticalAlignment="Top">
                            <TextBlock Text="{Binding Month, Converter={StaticResource monthConverter}}" Style="{StaticResource PhoneTextTitle2Style}" HorizontalAlignment="Left" VerticalAlignment="Top" Foreground="White" />
                            <TextBlock Text="{Binding Year}" Style="{StaticResource PhoneTextTitle2Style}" HorizontalAlignment="Right" VerticalAlignment="Bottom" Foreground="White" />
                        </Grid>
                    </DataTemplate>
                </toolkit:LongListSelector.GroupItemTemplate>
                <toolkit:LongListSelector.GroupHeaderTemplate>
                    <DataTemplate>
                        <Grid Background="{StaticResource PhoneAccentBrush}">
                            <TextBlock Text="{Binding Title}" Style="{StaticResource PhoneTextLargeStyle}" Foreground="White" />
                        </Grid>
                    </DataTemplate>
                </toolkit:LongListSelector.GroupHeaderTemplate>
                <toolkit:LongListSelector.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Rectangle Opacity="0.5" Visibility="{Binding IsActive, Converter={StaticResource visibilityConverter}}" Fill="{StaticResource PhoneAccentBrush}" />
                            <TextBlock Visibility="{Binding IsNotActive, Converter={StaticResource visibilityConverter}}" Text="{Binding WeekName}" Style="{StaticResource PhoneTextLargeStyle}" Tap="ListBox_Tap"/>
                            <TextBlock Visibility="{Binding IsActive, Converter={StaticResource visibilityConverter}}" Text="{Binding WeekName}" Style="{StaticResource PhoneTextLargeStyle}" Tap="ListBox_Tap" Foreground="White"/>
                        </Grid>
                    </DataTemplate>
                </toolkit:LongListSelector.ItemTemplate>
            </toolkit:LongListSelector>
        </Grid>
    </Grid>

</phone:PhoneApplicationPage>
